// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose:  Implementation of CXFormsElementOutput.
//   $Id$


#include "stdafx.h"
#include "OutputUI.h"
#include "output.h"
#include "multipleTextSource.h"
#include "parseOutput.h"
CXFormsElementOutput::CXFormsElementOutput()
{
	m_sControlName = "output";
	m_sInitialClassName = " output-value";
}

CXFormsElementOutput::~CXFormsElementOutput()
{

}

CImpl* CXFormsElementOutput::CreateImpl()
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState())

	CImpl* pImpl = (CImpl*) new CImplOutput(this);
	
	return pImpl;
}

CXFormsParse* CXFormsElementOutput::CreateParse(CImpl* pImpl)
{
	CXFormsParse* pParse = new CXFormsParseOutput((CImplOutput*) pImpl);

	return pParse;
}


STDMETHODIMP CXFormsElementOutput::handleEvent(IDOMEvent * pEvt)
{
	HRESULT hr = S_FALSE;
	if(pEvt)
	{
		CComBSTR sEventName;
		pEvt->get_type(&sEventName);
		// Remove will this is not a formcontrol
		if(m_pFormControl) 
		{
			if(sEventName == L"fp-uiready")
			{
				CImplMultipleTextSource * p = dynamic_cast<CImplMultipleTextSource *> (m_pFormControl);
				if(p)
				{
					BSTR sData = 0;
					p->GetMultipleTextSource(&sData);
					hr = onfp_putvalue(sData);
					::SysFreeString(sData);
				}
			}
			else
			{
				hr = __super::handleEvent(pEvt);
			}
		}
	}
	return hr;
}
